<template>
  <div class="content">
    <div class="top-lunbo">
      <el-carousel height="100vh">
        <el-carousel-item v-for="(item, i) in 2" :key="item">
          <div class="img-box" v-if="i == 0">
            <div class="title">
              <p>山东四度制冷科技有限公司</p>
              <span>
                防护式低温操作台
              </span>
              <h1>
                用途/适用范围：本产品适用于实验室、生物公司、医疗机构、制药厂、<br>食品加工等有温度控制需求的场所
              </h1>
            </div>
            <img v-if="i == 0" src="@/assets/lunbo/home2.jpg" alt="">
          </div>
          <div class="img-box" v-if="i == 1">
            <div class="title">
              <p>山东四度制冷科技有限公司</p>
              <span>
                平台式低温操作台
              </span>
              <h1>
                用途/适用范围：本产品适用于实验室、生物公司、医疗机构、制药厂、<br>食品加工等有温度控制需求的场所
              </h1>
            </div>
            <img src="@/assets/lunbo/home1.jpg" alt="">
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>
    <div class="chanpin-box">
      <div class="chanpin-item">
        <div class="left-box">
          <div class="title">
            产品中心
          </div>
          <span></span>
          <div class="message">
            专业提供实验室用低温操作台（工作台）、血液低温操作台（工作台） 医用洁净工作台、低温洁净工作台、低温配血台、血液配血台、低温操作台（工作台）价格、低温操作台（工作台）厂家
          </div>
          <div class="message-item">
            <div class="item" v-for="(item, i) in LeftList" :key="i" @click="gotoChanpin(item.record_id
)">
              {{ item.title }}
            </div>
          </div>
        </div>
        <div class="right-box">
          <div class="lunbo-2">
            <el-carousel height="680px">
              <el-carousel-item v-for="(item, i) in LeftList2" :key="i">
                <div class="item-box">
                  <div class="item" v-for="(item2, i2) in item.item" :key="i2">
                    <div class="title">
                      {{ item2.title }}
                    </div>
                    <div class="img">
                      <img :src="base64Img(item2.img)" alt="">
                    </div>
                    <div class="btn" @click="gotoChanpin(item2.record_id)">
                      点击查看
                    </div>
                  </div>
                </div>
              </el-carousel-item>
            </el-carousel>
          </div>
        </div>
      </div>
    </div>
    <div class="news-box">
      <div class="center">
        <div class="left-box">
          <div class="top-box">
            <p>新闻中心</p>
            <span>关注我们了解公司最新动态！</span>
          </div>
          <div class="img-box">
            <div class="img">
              <img v-if="firstData.img" :src="base64Img(firstData.img)" alt="">
            </div>
            <div class="title-box">
              <div class="time">最新消息</div>
              <div class="title">{{ firstData.title }}</div>
              <div class="btn" @click="gotoXiangqing(1,firstData.newsid)">查看详情</div>
            </div>
          </div>
        </div>
        <div class="right-box">
          <div class="top-btn-box">
            <div @click="gotoNewsView()">公司新闻</div>
            <div @click="gotoNewsView()">行业知识</div>
          </div>
          <div class="item-box" v-for="(item, index) in newsList" :key="index" >
            <div class="item" v-if="index <= 4" @click="gotoXiangqing(1,item.newsid)">
              <div class="left-index">
                {{ index + 1 }}
              </div>
              <div class="title">
                {{ item.title }}
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="bottom-box">
      <div class="box">
        <div class="item">
          <p class="p1">四度制冷为您服务</p>
          <p class="p2">四度制冷 专注打造您满意的产品</p>
        </div>
        <span></span>

        <div class="item">
          <div class="title">
            专属研发
          </div>
          <div class="p">山东制冷四度制冷科技有限公司</div>

        </div>
        <span></span>
        <div class="item">
          <div class="title">
            生产规模
          </div>
          <div class="p">山东制冷四度制冷科技有限公司</div>
        </div>
        <span></span>
        <div class="item">
          <div class="title">
            售后无忧
          </div>
          <div class="p">山东制冷四度制冷科技有限公司</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { getLeftList, getNewsList } from '@/api/viewapi.js'
import { onMounted, ref, reactive } from 'vue'
import { base64Img } from '@/tools/tools.js'
import router from '@/router/index.js';

const LeftList = ref([])
const LeftList2 = ref([])
const newsList = ref([])
const firstData = ref({})
// 左侧列表
const __getLeftData = () => {
  getLeftList().then((res) => {
    LeftList.value = res.data.data
    console.log('左侧信息', res);
    dataReact()
  })
}

// 获取新闻中心
const _getNewsList = () => {
  getNewsList().then((res) => {
    console.log('新闻列表', res);
    newsList.value = res.data.newslist
    firstData.value = res.data.newslist[0]

  })
}


// 跳转详情
const gotoXiangqing = (checkid,newsid) =>{
    router.push({path:'/newsmessage',query:{
        checkid:checkid,newsid
    }})
}
// 跳转详情
const gotoChanpin = (id) => {
    router.push({path:'/chanpinlist',query:{id:id}})
}
// 跳转新闻页面
const gotoNewsView = () => {
  router.push({path:'/news'})
 }

// 轮播图数据处理
const dataReact = () => {
  let data = LeftList.value
  let pushData = []
  let item = []
  for (let i = 0; i < data.length; i++) {

    item.push(data[i])

    if (item.length === 6) {
      pushData.push({ item })
      item = []
    }
  }

  // 如果最后剩下不足 3 个元素，仍然需要推入
  if (item.length > 0) {
    pushData.push({ item });
  }

  LeftList2.value = pushData
  console.log('最后结果', pushData);
}

// 获取新闻列表


onMounted(() => {
  __getLeftData()
  _getNewsList()
});

</script>
<style lang="scss" scoped>
.content {
  .top-lunbo {

    .img-box {
      position: relative;

      .title {
        position: absolute;
        left: 200px;
        top: 280px;
        color: white;

        p {
          font-size: 22px;
          font-weight: 400;
        }

        span {
          font-size: 67px;
          font-weight: 700;
          line-height: 140px;

        }

        h1 {
          font-size: 18px;
          line-height: 40px;
        }
      }
    }

  }

  .chanpin-box {
    padding: 100px 0;
    background-color: #e8f0f3;

    .chanpin-item {
      max-width: 1400px;
      margin: 0 auto;
      display: flex;

      .left-box {
        margin-right: 80px;

        .title {
          font-size: 46px;
          margin-bottom: 20px;
        }

        span {
          display: block;
          width: 80px;
          height: 4px;
          background-color: #00a0e9;
        }

        .message {
          margin-top: 20px;
          width: 430px;
          line-height: 28px;
          font-size: 14px;
          font-weight: 400;
        }

        .message-item {
          margin-top: 80px;
          width: 430px;
          display: grid;
          grid-template-columns: repeat(2, 1fr);
          gap: 16px;

          .item {
            padding: 18px;
            background-color: #ffffff;
            border-radius: 10px;
            border: 1px solid gainsboro;
            cursor: pointer;
            transition: transform 0.3s ease, background-color 0.3s ease;
          }

          .item:hover {
            background-color: #00a0e9;
            color: white;
            transform: scale(1.08);
          }
        }
      }

      .right-box {
        width: 100%;
        display: block;

        .lunbo-2 {
          display: block;

          .item-box {
            display: block;
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            /* 定义三列 */
            gap: 10px;
            /* 每个网格之间的间隙 */

            .item {
              padding: 20px;
              background-color: rgb(255, 255, 255);
              width: 240px;
              border-radius: 20px;
              border: 1px solid gainsboro;
              transition: transform 0.3s ease, background-color 0.3s ease;
              cursor: pointer;

              .title {
                font-size: 22px;
                text-align: center;
              }

              .img {
                padding-top: 10px;
                padding-bottom: 10px;

                img {
                  width: 100%;
                }
              }

              .btn {
                padding: 10px 0;
                color: #f25930;
                text-align: center;
                border: 1px solid #f25930;
                border-radius: 10px;
              }
            }

            .item:hover {
              background-color: #00a0e9;
              color: white;
              transform: scale(1.01);

              .btn {
                color: white;

                border: 1px solid #ffffff;
              }
            }
          }
        }
      }
    }
  }

  .news-box {
    padding: 100px 0;

    .center {
      max-width: 1400px;
      margin: 0 auto;
      display: flex;
      justify-content: space-between;

      .left-box {
        .top-box {
          padding-bottom: 20px;

          p {
            font-weight: 400;
            font-size: 46px;
            margin-bottom: 10px;
          }

          span {}
        }

        .img-box {
          display: flex;
          justify-content: space-between;
          width: 840px;
          height: 500px;
          background-color: wheat;
          transition: transform 0.3s ease, background-color 0.3s ease;

          .img {
            width: 500px;
            height: 500px;
            background-color: #dbf3ff;
            flex-direction: column;
            display: flex;
            justify-content: center;

            img {
              width: 100%;
            }

          }

          .title-box {
            z-index: 99;
            width: 340px;
            background-color: #ebf3f7;
            padding: 80px 40px 40px 40px;

            .time {
              font-size: 26px;
              margin-bottom: 40px;
              font-weight: 200;
            }

            .title {

              line-height: 34px;
              font-weight: 800;
              font-size: 22px;
              margin-bottom: 20px;
            }

            .btn {
              padding: 16px 10px;
              border: 1px solid white;
              width: 100px;
              text-align: center;
              border-radius: 10px;
              color: white;
              background-color: #00a0e9;
              cursor: pointer;
              transition: transform 0.3s ease, background-color 0.3s ease;

            }

            .btn:hover {
              background-color: orange;
            }

          }
        }

        .img-box:hover {
          z-index: -1;
          transform: scale(1.01);
        }
      }

      .right-box {
        .top-btn-box {
          display: flex;
          padding-bottom: 60px;

          div {
            padding: 14px 60px;
            border: 1px solid rgb(0, 0, 0);
            margin-left: 40px;
            border-radius: 10px;
            transition: transform 0.3s ease, background-color 0.3s ease;
            cursor: pointer;
          }

          div:hover {
            background-color: #00a0e9;
            color: white;
            border: 1px solid rgb(255, 255, 255);

          }
        }

        .item-box {
          .item {
            width: 100%;
            background-color: #ffffff;
            display: flex;
            border: 1px solid #ebf3f7;
            margin-bottom: 40px;
            transition: transform 0.3s ease, background-color 0.3s ease;

            .left-index {
              margin-right: 40px;
              padding: 20px 30px;
              height: 100%;
              background-color: #ebf3f7;
            }

            .title {
              line-height: 60px;
              overflow: hidden;
              white-space: nowrap;
              width: 390px;
              padding-right: 30px;
            }
          }

          .item:hover {
            border: 1px solid #00a0e9;
            cursor: pointer;
            transform: scale(1.01);

            .left-index {
              background-color: #00a0e9;
              color: white;
            }
          }
        }
      }
    }
  }

  .bottom-box {
    padding: 40px 0;
    background-color: #ebf3f7;

    .box {
      max-width: 1400px;
      margin: 0 auto;
      display: flex;
      justify-content: space-between;

      span {
        display: block;
        height: 120px;
        width: 1px;
        background-color: #c0c0c0;
      }

      .item {
        padding: 20px 0;

        .p1 {
          line-height: 54px;
          font-size: 36px;
          font-weight: 700;
          color: #00a0e9;
        }

        .title {
          margin-top: 14px;
          font-size: 24px;
        }

        .p {
          text-align: center;
        }
      }

    }
  }
}
</style>